#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

typedef struct Usr
{
	int iId;
	char caName[32];
	float fScore;
	struct Usr *next;
}Usr;

int main(int argc, char *argv[])
{	
	if (2 != argc)
	{
		exit(EXIT_FAILURE);
	}
	FILE *file = fopen(argv[1], "rb");
	Usr usr;
	fread(&usr, sizeof(Usr), 1, file);
	printf("id=%d,name=%s,score=%.1f\n"
		   , usr.iId, usr.caName, usr.fScore);
	
	//从当前位置往后偏移3*sizeof(Usr)字节
	//off_t offset = 3*sizeof(Usr);
	//fseek(file, offset, SEEK_CUR);

	fseek(file, 4*sizeof(Usr), SEEK_SET);
	fread(&usr, sizeof(Usr), 1, file);
	printf("id=%d,name=%s,score=%.1f\n"
		   , usr.iId, usr.caName, usr.fScore);

	off_t offset = -6*sizeof(Usr);	
	fseek(file, offset, SEEK_END);
	fread(&usr, sizeof(Usr), 1, file);
	printf("id=%d,name=%s,score=%.1f\n"
		   , usr.iId, usr.caName, usr.fScore);
	
	fclose(file);

	return 0;
}
